﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace ComToolkit.IO
{
    public static class Directory
    {
        public static DirectoryInfo CreateDirectory(string path)
        {
            return new DirectoryInfo(FileSystemObject.Get().CreateFolder(path));
        }

        public static void Delete(string path)
        {
            FileSystemObject.Get().DeleteFolder(path);
        }

        public static bool Exists(string path)
        {
            return FileSystemObject.Get().FolderExists(path);
        }

        public static string[] GetDirectories(string path)
        {
            return EnumerateDirectories(path).ToArray();
        }

        public static IEnumerable<string> EnumerateDirectories(string path)
        //, string searchPattern, SearchOption searchOption)
        {
            if (!Exists(path))
            {
                throw new ArgumentException("path");
            }
            dynamic folder = FileSystemObject.Get().GetFolder(path);
            foreach (dynamic f in folder.SubFolders)
            {
                string n = f.name;
                yield return n;
            }
        }

        public static string GetDirectoryRoot(string path)
        {
            throw new NotImplementedException();
        }
        public static string[] GetFiles(string path) //, string searchPattern, SearchOption searchOption)
        {
            return EnumerateFiles(path).ToArray();
        }

        public static IEnumerable<string> EnumerateFiles(string path) //, string searchPattern, SearchOption searchOption)
        {
            if (!Exists(path))
            {
                throw new ArgumentException("path");
            }
            dynamic folder = FileSystemObject.Get().GetFolder(path);
            foreach (dynamic f in folder.Files)
            {
                string n = f.name;
                yield return n;
            }
        }

        public static IEnumerable<DriveInfo> GetLogicalDrives()
        {
            foreach (dynamic drive in FileSystemObject.Get().Drives)
            {
                yield return new DriveInfo(drive);
            }
        }

        public static DirectoryInfo GetParent(string path)
        {
            return new DirectoryInfo(
                FileSystemObject.Get().GetFolder(
                    FileSystemObject.Get().GetParentFolderName(path)
                    ));
        }

        public static void Move(string sourceDirName, string destDirName)
        {
            throw new NotImplementedException();
        }
    }
}